package OrderedCoverPackage;

import DataSetPackage.View;
import EstimatorPackage.EstimatorExp;
import HierarchyPackage.Hierarchy;

import java.util.Collection;
import java.util.List;

/**
 *
 * @author Martin Haulrich
 */
public abstract class AbstractTrainOC extends AbstractOC {

    public AbstractTrainOC(Hierarchy hier, EstimatorExp prior) {
        super(hier, prior);
    }
    /**
     * A map containing the prior-probabilities of all data points in the cover.
     */
    public List<Double> priorDataPointProbs;

    /**
     * Return the ID that should be used if a new partition is created.
     * @return ID that should be used if a new partition is created.
     */
    protected abstract int nextID();

    /**
     * Returns the number of data points used to train the cover
     * All data points are as such still present in the cover
     * @return Number of datapoints used to train cover.
     */
    public abstract int dataSize();

    /**
     * Returns data points for a given partition
     * @param partition Partition to get datapoints from.
     * @return Datapoints located in partition.
     */
    protected abstract Collection<Integer> getData(OCPartitionTrain partition);

    /**
     * For a given set of data return the prior log-likekelighood for these datapoints.
     * @param dataPoints Datapoints to find prior log-likelihood for.
     * @return Prior log-likelighood for datapoints.
     */
    protected double priorLogLik(Collection<Integer> dataPoints) {
        double logLik = 0;
        for (Integer did : dataPoints) {
            /**
             * @TODO This call only works if train has been called. Otherwhise 'priorDataPointProbs' is not initialized.
             */
            double l = priorDataPointProbs.get(did);
            logLik = logLik + l;
        }

        return logLik;
    }

    /**
     * Get prior log-likehood for datapoints in partition.
     * @param partition Partition that holds the datapoints to get the prior-log-likelihood of.
     * @return Prior log-likelighood for datapoints in partition.
     */
    protected abstract double getPriorLogLik(OCPartitionTrain partition);

    /**
     * Returns the log-likelihood for the datapoints in a given partiotin.
     * The view is required in order to acces the original dataset.
     * @param partition Partition which hold the datapoints to get the log-likelihood for.
     * @param view View on datapoints.
     * @return Log-likelihood for datapoints in partition.
     */
    protected abstract double getLogLikelihood(OCPartition partition, View view);

    /**
     * Returns the bump post weigth of a given partition.
     * The view is required in order to acces the original dataset.
     * @param view View on datapoints.
     * @return BumpPostMDL for cover.
     */
    public abstract double getBumpPostMDL(View view);
}
